home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form Form1
- BackColor = &H00000000&
- BorderStyle = 0 'None
- Caption = "Form1"
- ClientHeight = 7200
- ClientLeft = 0
- ClientTop = 0
- ClientWidth = 9600
- FillStyle = 0 'Solid
- Icon = "main.frx":0000
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 480
- ScaleMode = 3 'Pixel
- ScaleWidth = 640
- ShowInTaskbar = 0 'False
- StartUpPosition = 2 'CenterScreen
- WindowState = 2 'Maximized
- Begin VB.Frame Frame1
- BackColor = &H00000000&
- Caption = "-=Game=-"
- BeginProperty Font
- Name = "Fixedsys"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- ForeColor = &H000000FF&
- Height = 7095
- Left = 7200
- TabIndex = 0
- Top = 0
- Width = 2295
- Begin VB.CommandButton btnOutPut
- DisabledPicture = "main.frx":0E42
- DownPicture = "main.frx":21FC
- BeginProperty Font
- Name = "Comic Sans MS"
- Size = 14.25
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 495
- Left = 120
- Picture = "main.frx":502E
- Style = 1 'Graphical
- TabIndex = 6
- Top = 2520
- Width = 2055
- End
- Begin VB.CommandButton btnPlay
- DisabledPicture = "main.frx":7E60
- DownPicture = "main.frx":921A
- BeginProperty Font
- Name = "Fixedsys"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 495
- Left = 120
- Picture = "main.frx":C04C
- Style = 1 'Graphical
- TabIndex = 5
- TabStop = 0 'False
- Top = 1080
- Width = 2055
- End
- Begin VB.CommandButton btnQuit
- DisabledPicture = "main.frx":EE7E
- DownPicture = "main.frx":10238
- BeginProperty Font
- Name = "Fixedsys"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 495
- Left = 120
- Picture = "main.frx":1306A
- Style = 1 'Graphical
- TabIndex = 4
- TabStop = 0 'False
- Top = 6360
- Width = 2055
- End
- Begin VB.CommandButton btnPauseResume
- DisabledPicture = "main.frx":15E9C
- DownPicture = "main.frx":17256
- BeginProperty Font
- Name = "Fixedsys"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 495
- Left = 120
- Picture = "main.frx":1A088
- Style = 1 'Graphical
- TabIndex = 1
- TabStop = 0 'False
- Top = 1800
- Width = 2055
- End
- Begin VB.Label Label2
- BackStyle = 0 'Transparent
- Caption = "Player2:"
- BeginProperty Font
- Name = "Fixedsys"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- ForeColor = &H00FF0000&
- Height = 255
- Left = 120
- TabIndex = 3
- Top = 600
- Width = 2055
- End
- Begin VB.Label Label1
- BackStyle = 0 'Transparent
- Caption = "Player1:"
- BeginProperty Font
- Name = "Fixedsys"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- ForeColor = &H000000FF&
- Height = 255
- Left = 120
- TabIndex = 2
- Top = 360
- Width = 2055
- End
- End
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- ' Most of the game stuff if stuck in here... Feel free to browse the mess! It all works
- ' btw!!! :)
- ' This is the main game loop flag. To exit the program, just make bActive false
- Private bActive As Boolean
- ' This is the playing loop flag. To pause the game from playing, make this false
- Private bPaused As Boolean
- ' If the game screen should be refreshed (Redrawn), set this to false
- Private bRefreshed As Boolean
- ' This is player1
- Private Player1 As New Player
- ' This is player 2
- Private Player2 As New Player
- ' This is our customised, and infinitely kooler, messagebox
- Private MesBox As New MessBox
- ' Game input. Uses my own class wrapper for DirectInput which is part of the CDXVB
- ' library of class wrappers for DirectX in VB
- Private GameIN As New CDXVBInput
- Private GameMusic As New CDXVBMusic
- Private Sub btnOutPut_Click()
- GameIN.UnAcquire
- OutPutfrm.Show vbModal, Me
- GameIN.ReAcquire
-
- ' Redraw the screen
- bRefreshed = False
- End Sub
- Private Sub btnPauseResume_Click()
- ' If the game is currently paused then load new bitmaps into pause/resume button
- ' Otherwise, load other bitmaps
- If bPaused Then
- ' This little thang I thunk up is well handy... Checks to see if you are
- ' in the root of the drive (\), if so, then load bitmaps without the '\'
- ' in the pathname! (Prevents crashing when running from root like some
- ' people may wish to)
- If Mid(App.Path, 2, 1) = "\" Then
- btnPauseResume.Picture = LoadPicture(App.Path & "PAUSE.BMP")
- btnPauseResume.DisabledPicture = LoadPicture(App.Path & "PAUSEOFF.BMP")
- btnPauseResume.DownPicture = LoadPicture(App.Path & "PAUSEDOWN.BMP")
- Else
- btnPauseResume.Picture = LoadPicture(App.Path & "\PAUSE.BMP")
- btnPauseResume.DisabledPicture = LoadPicture(App.Path & "\PAUSEOFF.BMP")
- btnPauseResume.DownPicture = LoadPicture(App.Path & "\PAUSEDOWN.BMP")
- End If
- bPaused = False
- Else
- If Mid(App.Path, 2, 1) = "\" Then
- btnPauseResume.Picture = LoadPicture(App.Path & "RESUME.BMP")
- btnPauseResume.DisabledPicture = LoadPicture(App.Path & "RESUMEOFF.BMP")
- btnPauseResume.DownPicture = LoadPicture(App.Path & "RESUMEDOWN.BMP")
- Else
- btnPauseResume.Picture = LoadPicture(App.Path & "\RESUME.BMP")
- btnPauseResume.DisabledPicture = LoadPicture(App.Path & "\RESUMEOFF.BMP")
- btnPauseResume.DownPicture = LoadPicture(App.Path & "\RESUMEDOWN.BMP")
- End If
- bPaused = True
- End If
- End Sub
- Private Sub btnPlay_Click()
- ' Enable the pause/resume button
- btnPauseResume.Enabled = True
-
- If Mid(App.Path, 2, 1) = "\" Then
- GameMusic.Play App.Path & "InGame.mid"
- Else
- GameMusic.Play App.Path & "\InGame.mid"
- End If
-
- GameIN.UnAcquire
- Countfrm.Show vbModal, Me
- GameIN.ReAcquire
-
- ' Unpause the game
- bPaused = False
- ' Disable the new-game button
- btnPlay.Enabled = False
- End Sub
- Private Sub btnQuit_Click()
- ' Shut down the main game loop
- bActive = False
- End Sub
- Private Sub Form_Load()
- ' Activate main game loop
- bActive = True
- ' Pause the game
- bPaused = True
- ' Our game screen doesn't require refreshing!
- bRefreshed = True
- ' Show the form (Wont get done becuz of loop unless we force it here
- Me.Show
-
- ' Init the buffer
- Call ScrBufInit
-
- ' Play MIDI music! (yay)
- GameMusic.Init Me.hWnd
- If Mid(App.Path, 2, 1) = "\" Then
- GameMusic.Play App.Path & "Music.mid"
- Else
- GameMusic.Play App.Path & "\Music.mid"
- End If
- ' Player 1
- Player1.Create Me.hDC, 0, 0, RGB(255, 0, 0), 1
- Player1.ChangeDir DIR_RIGHT
- Player1.ChangeDir DIR_STOPY
- ' Player 2
- Player2.Create Me.hDC, (GetSystemMetrics(SM_CXSCREEN) - 3) - Frame1.Width, GetSystemMetrics(SM_CYSCREEN) - 3, RGB(0, 0, 255), 2
- Player2.ChangeDir DIR_LEFT
- Player2.ChangeDir DIR_STOPY
-
- ' Disable pause/resume button until a new game is started!
- btnPauseResume.Enabled = False
- ' Init GUID's...
- Call GUID_Initialize
- ' Create input device
- GameIN.Create App.hInstance, Me.hWnd
-
- ' Acquire the kb/mouse input devices
- GameIN.ReAcquire
-
- ' Show the form (again) to force a decent repaint
- Me.Show
- ' Main game loop
- While (bActive)
- ' Process windows messages
- DoEvents
-
- If bRefreshed = False Then
- ' Redraw stuff
- For X = 0 To UBound(ScrArr, 1)
- For Y = 0 To UBound(ScrArr, 2)
- If ScrArr(X, Y) = 1 Then
- SetPixel Me.hDC, X, Y, RGB(255, 0, 0)
- ElseIf ScrArr(X, Y) = 2 Then
- SetPixel Me.hDC, X, Y, RGB(0, 0, 255)
- End If
- Next Y
- Next X
- bRefreshed = True
- End If
-
- If Not bPaused Then
- ' Update game input
- Call CheckInput
-
- ' Move objects
- Call MoveObjs
-
- ' Test for collisions on objects
- Call CollisionObjs
-
- ' Draw objects
- Call DrawObjs
- End If
- Wend
-
- ' Unacquire the input devices
- GameIN.UnAcquire
-
- GameMusic.StopPlaying
-
- ' Unload the form
- Unload Me
- End Sub
- Private Sub CheckInput()
- ' Get latest keyboard input data
- GameIN.UpdateKeyboard
-
- If Keys(DIK_W) Then
- Player1.ChangeDir DIR_UP
- Player1.ChangeDir DIR_STOPX
- End If
- If Keys(DIK_S) Then
- Player1.ChangeDir DIR_DOWN
- Player1.ChangeDir DIR_STOPX
- End If
- If Keys(DIK_A) Then
- Player1.ChangeDir DIR_LEFT
- Player1.ChangeDir DIR_STOPY
- End If
- If Keys(DIK_D) Then
- Player1.ChangeDir DIR_RIGHT
- Player1.ChangeDir DIR_STOPY
- End If
-
- If Keys(DIK_UP) Then
- Player2.ChangeDir DIR_UP
- Player2.ChangeDir DIR_STOPX
- End If
- If Keys(DIK_DOWN) Then
- Player2.ChangeDir DIR_DOWN
- Player2.ChangeDir DIR_STOPX
- End If
- If Keys(DIK_LEFT) Then
- Player2.ChangeDir DIR_LEFT
- Player2.ChangeDir DIR_STOPY
- End If
- If Keys(DIK_RIGHT) Then
- Player2.ChangeDir DIR_RIGHT
- Player2.ChangeDir DIR_STOPY
- End If
- End Sub
- Private Sub MoveObjs()
- ' Move objects (2 players)
- Player1.Move
- Player2.Move
-
- ' Update player position labels (Used for slowing down the game!)
- Label1.Caption = "Player1: " & Player1.m_PosX & ", " & Player1.m_PosY
- Label2.Caption = "Player2: " & Player2.m_PosX & ", " & Player2.m_PosY
- End Sub
- Private Sub CollisionObjs()
- ' If there is a collision between either of the players
- If Player1.Collision(Player2) Then
- GameIN.UnAcquire
- MesBox.Change "Player2 won!"
- MesBox.ShowIt Me
- Call NewGame
- Exit Sub
- End If
- If Player2.Collision(Player1) Then
- GameIN.UnAcquire
- MesBox.Change "Player1 won!"
- MesBox.ShowIt Me
- Call NewGame
- Exit Sub
- End If
- End Sub
- Private Sub DrawObjs()
- ' Draw objects (2 players)
- Player1.Draw
- Player2.Draw
- End Sub
- Private Sub Form_Resize()
- ' Resize the main-game frame
- Frame1.Top = 0
- Frame1.Left = Me.ScaleWidth - Frame1.Width
- Frame1.Height = Me.ScaleHeight
-
- ' Move the quit button
- btnQuit.Top = ((GetSystemMetrics(SM_CYSCREEN)) * 14) - (10 * 14)
- End Sub
- Private Sub NewGame()
- ' Clear the screen (And thus, erase last game)
- Cls
-
- ' Init(AND clear) screen array
- Call ScrBufInit
-
- ' REACQUIRE the game input devices...
- GameIN.ReAcquire
- ' Pause the game
- bPaused = True
- ' Player 1
- Player1.Create Me.hDC, 0, 0, RGB(255, 0, 0), 1
- Player1.ChangeDir DIR_NEWGAME
- Player1.ChangeDir DIR_RIGHT
- Player1.ChangeDir DIR_STOPY
- ' Player 2
- Player2.Create Me.hDC, (GetSystemMetrics(SM_CXSCREEN) - 3) - Frame1.Width, GetSystemMetrics(SM_CYSCREEN) - 3, RGB(0, 0, 255), 2
- Player2.ChangeDir DIR_NEWGAME
- Player2.ChangeDir DIR_LEFT
- Player2.ChangeDir DIR_STOPY
-
- ' Enable newgame button
- btnPlay.Enabled = True
-
- If Mid(App.Path, 2, 1) = "\" Then
- GameMusic.Play App.Path & "Music.mid"
- Else
- GameMusic.Play App.Path & "\Music.mid"
- End If
-
- ' Disable pause/resume button until a new game is started!
- btnPauseResume.Enabled = False
- End Sub
-